//
//  MessageViewController.m
//  Hui
//
//  Created by HawkingWang on 16/10/26.
//  Copyright © 2016年 Hui. All rights reserved.
//

#import "MessageViewController.h"
#import "MessageTableViewCell.h"//cell

@interface MessageViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation MessageViewController
{
    NSMutableArray *_cellHeight;
}

 static NSString *const MessageTableViewCellID = @"MessageTableViewCell";

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.navigationController.navigationBar.hidden = NO;
    
    //设置导航栏
    [self setNav];
    
    //注册TableView
    [self registerTableView];
}

- (void)setNav{
    
    UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64)];
    navView.backgroundColor = APPCOLOR;
    [self.view addSubview:navView];
    
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - 38) / 2, 29, 38, 26.5)];
    title.text =  @"消息";
    title.font = [UIFont fontWithName:APPFONT size:19];
    title.textColor = [UIColor whiteColor];
    title.textAlignment = NSTextAlignmentCenter;
    [navView addSubview:title];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 20, 49, 44);
    [button addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
    [navView addSubview:button];
    
    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(15, 13.5, 19, 19)];
    image.image = [UIImage imageNamed:@"top-off"];
    [button addSubview:image];
    
    
//    self.navigationItem.title = @"消息";
//    UIButton *close = [UIButton buttonWithType:UIButtonTypeCustom];
//    close.frame = CGRectMake(0, 0, 19, 44);
//    [close addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
//    UIImageView *closeImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 13.5, 19, 19)];
//    closeImage.image = [UIImage imageNamed:@"top-off"];
//    [close addSubview:closeImage];
//    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:close];
//    self.navigationItem.leftBarButtonItem = leftItem;
}
#pragma mark === 注册TableView ===
- (void)registerTableView{
    _cellHeight = [NSMutableArray array];
    for (int i = 0; i < 2; i++) {
        [_cellHeight addObject:@"0"];
    }
    
    [self.tableView registerClass:[MessageTableViewCell class] forCellReuseIdentifier:MessageTableViewCellID];
}

#pragma mark === UITableViewDelegate ===
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [_cellHeight[indexPath.row] floatValue];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MessageTableViewCellID];
    if (!cell) {
        cell = [[MessageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MessageTableViewCellID];
    }
    [cell setViewWithMessage:@"系统消息内容系统消息内容系统消息内容系统消息内容系统消息内容系统消息内容系统消息内容系统消息内容系统消息内容系统消息内容系统消息内容系统消息内容" andTime:@"2016.06.16 11:34"];
    [_cellHeight replaceObjectAtIndex:indexPath.row withObject:[NSString stringWithFormat:@"%f", cell.height]];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)close{
    [self.navigationController popViewControllerAnimated:YES];
}


- (UITableView *)tableView{
    if (!_tableView) {
        _tableView= [[UITableView alloc]initWithFrame:CGRectMake(0,64, SCREEN_WIDTH, SCREEN_HEIGHT - 64)style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.showsVerticalScrollIndicator = NO;//去掉滑动竖条
        _tableView.backgroundColor = RGBCOLOR(236, 236, 236);
        [self.view addSubview:_tableView];
    }
    return _tableView;
}
     

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
